package com.ecoolex.discount.sales.api.graphql;

import com.ecoolex.discount.sales.entity.DiscountBrandWithBLOBs;
import com.ecoolex.discount.sales.entity.DiscountClassify;
import com.ecoolex.discount.sales.entity.DiscountProductWithBLOBs;
import com.ecoolex.discount.sales.pojo.QueryOnlineDiscountProductDTO;
import com.ecoolex.discount.sales.ws.DiscountProductService;
import com.ecoolex.framework.modularize.api.service.storage.StorageInfo;
import com.ecoolex.framework.modularize.api.service.storage.StorageService;
import com.ecoolex.framework.web.api.graphql2.annotation.GraphQL2Module;
import com.ecoolex.framework.web.api.graphql2.annotation.QueryField;
import com.ecoolex.framework.web.api.graphql2.annotation.Source;
import com.ecoolex.framework.web.api.graphql2.annotation.TypeField;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.lang.NonNull;

import java.util.List;

@GraphQL2Module(type = GraphQL2Module.Type.User, description = "折扣品牌")
public class DiscountBrandGraphql {

    @Autowired
    private StorageService storageService;
    @Reference
    private DiscountProductService discountProductService;

    @TypeField(type = DiscountBrandWithBLOBs.class, field = "logo", description = "折扣品牌Logo")
    public StorageInfo logo(@Source DiscountBrandWithBLOBs source) {
        return storageService.get(source.getLogo());
    }

    @TypeField(type = DiscountBrandWithBLOBs.class, field = "image", description = "折扣品牌展示图")
    public StorageInfo image(@Source DiscountBrandWithBLOBs source) {
        return storageService.get(source.getImage());
    }

    @TypeField(type = DiscountBrandWithBLOBs.class, field = "productList", description = "产品列表")
    public List<DiscountProductWithBLOBs> productList(@Source DiscountBrandWithBLOBs source, @NonNull Integer regionType, @NonNull Integer discountMode, @NonNull Integer size) {
        QueryOnlineDiscountProductDTO query = new QueryOnlineDiscountProductDTO();
        query.setBrandId(source.getBrandId());
        query.setRegionType(regionType);
        query.setDiscountMode(discountMode);
        return discountProductService.queryProductByOnline(query, size);
    }
    
    @TypeField(type = DiscountBrandWithBLOBs.class, field = "discountClassify", description = "所属折扣分类")
    public DiscountClassify discountClassify(@Source DiscountBrandWithBLOBs source,@NonNull Integer regionType) {
    	return discountProductService.getDiscountClassifyByBrandIdForH5(source.getBrandId(), regionType);
    }

    @QueryField(field = "discountBrand",description = "折扣品牌详情")
    public DiscountBrandWithBLOBs get(@NonNull Integer brandId) {
    	return discountProductService.getDiscountBrandForH5(brandId);
    }
}
